/**
 *
 * @author marc.molins.piulachs
 */

package domain;

import java.util.ArrayList;

public class TextController {

	private Text _text;
	private int _id;
	private static TextController singleton;


	public static TextController getInstance() {
		if(singleton == null) {
			singleton = new TextController();
		}
		return singleton;
	}

	public void newText(int id) {
		DictionaryController dc = new DictionaryController();
		_text = null;
		_text = new Text(dc.createVerbDictionary(id), dc.createNounDictionary(id));
		_id = id;
	}

	public void enterText(String txt) {
		_text.enterText(txt);
	}

	public ArrayList< Pair<String,Float> > startNominalization() {
		_text.startNominalization();
		return _text.getCurrentNounsAndProbability();
	}

	public ArrayList<Integer> getPositions() {
		return _text.getPositions();
	}

	public ArrayList< Pair<String,Float> > nextNominalization() {
		_text.nextNominalization();
		return _text.getCurrentNounsAndProbability();
	}

	public ArrayList< Pair<String,Float> > previousNominalization() {
		_text.previousNominalization();
		return _text.getCurrentNounsAndProbability();
	}

	public ArrayList< Pair<String,Float> > clickNominalization(int textPosition) {
		_text.clickVerb(textPosition);
		return _text.getCurrentNounsAndProbability();
	}

    public int getCurrentNominalizationPosition() {
        return _text.getCurrentNominalizationPosition();
    }

	public String getText() {
		return _text.getText();
	}


	public void favoriteNominalization(int position) {
		Pair<String,String> p = _text.favoriteNominalization(position);
		DictionaryController dc = new DictionaryController();
		dc.addTrainingPair(p.first, p.second, _id);
	}

	public void enterTextOnly(String txt) {
		_text.enterTextOnly(txt);
	}

}
